package my.jieh.tips.util.jar;

import java.io.*;
import java.util.jar.*;

/**
 * <p>Title: Core Java Technologies Tech Tips</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2002</p>
 * <p>Company: Blueimp</p>
 * @author jieh
 * @version 1.0
 */

public class JarRead {
  public static void main(String args[]) throws IOException {
    /*
         if (args.length != 2) {
      System.out.println("Please provide a JAR filename and file to read");
      System.exit( -1);
         }
         JarFile jarFile = new JarFile(args[0]);
         JarEntry entry = jarFile.getJarEntry(args[1]);
     */
    JarFile jarFile = new JarFile("Java2Demo.jar");
    java.util.jar.Manifest manifest = jarFile.getManifest();
//    manifest.getAttributes()

    JarEntry entry = jarFile.getJarEntry("Manifest.mf");
//    JarEntry entry = jarFile.getJarEntry("junk.txt");
    InputStream input = jarFile.getInputStream(entry);
    process(input);
  }

  private static void process(InputStream input) throws IOException {
    InputStreamReader isr = new InputStreamReader(input);
    BufferedReader reader = new BufferedReader(isr);
    String line;
    while ( (line = reader.readLine()) != null) {
      System.out.println(line);
    }
    reader.close();
  }
}